package org.bim.view.drag.design.util;


import org.bim.view.drag.design.exception.BizCommonException;

/**
 * 业务异常工具类,方便一些业务判断, 断言的异常均需为{@link BizCommonException}或其的子类
 *
 * @author bim-view
 * @date 2021-07-13
 */

public class AssertUtil {
    private AssertUtil() {
    }

    /**
     * 断言为false, 则抛出 自定义的exception
     *
     * @param value
     * @param exception 必须为BizCommonException子类
     * @param <E>
     */
    public static <E extends BizCommonException> void isTrue(boolean value, E exception) {
        if (!value) {
            throw exception;
        }
    }

    /**
     * 若断言为false, 则抛出 {@link BizCommonException}, 默认msg
     *
     * @param value
     */
    public static void isTrue(boolean value) {
        if (!value) {
            throw new BizCommonException();
        }
    }

    /**
     * 若断言为false, 则抛出 {@link BizCommonException}, 指定msg
     *
     * @param value
     * @param msg
     */
    public static void isTrue(boolean value, String msg) {
        if (!value) {
            throw new BizCommonException(msg);
        }
    }

}
